/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.apt.countrytag;


import com.apt.tag.Connect_DB;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Bach
 */
public class EnableCountry {

    public static boolean setEnableCountry(String country_Name, String country_Id) {

        String up = "UPDATE [Matrimony].[dbo].[Countries]\n"
                + "   SET [Country_Status] = 1\n"
                + " WHERE Country_Id=? ";
        boolean re = false;
        Connection con = null;
        PreparedStatement ps = null;
        try {
            con = Connect_DB.getConnection();
            con.setAutoCommit(false);// transaction
            ps = con.prepareStatement(up);
            ps.setInt(1, Integer.parseInt(country_Id));
            int i = ps.executeUpdate();
            if (i > 0) {
                if (setEnableCity(country_Id, con)) {
                    re = true;
                }
            }
            con.commit();
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                con.rollback();
            } catch (SQLException ex) {
                Logger.getLogger(EnableCountry.class.getName()).log(Level.SEVERE, null, ex);
            }
        } finally {
            Connect_DB.close(null, null, ps, con);
        }
        return re;
    }

    public static boolean setEnableCity(String country_Id, Connection con) {
        String up = "UPDATE [Matrimony].[dbo].[Cities]\n"
                + "   SET [City_Status] = 1\n"
                + " WHERE [Country_Id]=?";

        boolean re = false;
        PreparedStatement ps = null;
        try {

            ps = con.prepareStatement(up);
            ps.setInt(1, Integer.parseInt(country_Id));
            int i = ps.executeUpdate();
            if (i > 0) {
                re = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return re;
    }
//     public static boolean setDisableHobbies(String hobbies_Name, String liking_Model_Id,String liking_Id) {
//        String up = "UPDATE [Matrimony].[dbo].[Liking_Models]\n"
//                + "   SET [Liking_Model_Status] = 0\n"
//                + " where [Liking_Model_Name]=? and [Liking_Model_Id]=?";
//
//        boolean re = false;
//        Connection con = null;
//        PreparedStatement ps = null;
//        try {
//            con = Connect_DB.getConnection();
//            con.setAutoCommit(false);// transaction
//            ps = con.prepareStatement(up);
//            ps.setString(1, hobbies_Name);
//            ps.setInt(2, Integer.parseInt(liking_Model_Id));
//            int i = ps.executeUpdate();
//            if (i > 0) {
//                if (setDisableLiking(liking_Id, con)) {
//                    re = true;
//                }
//            }
//            con.commit();
//        } catch (SQLException e) {
//            e.printStackTrace();
//            try {
//                con.rollback();
//            } catch (SQLException ex) {
//                Logger.getLogger(DisableHobbies.class.getName()).log(Level.SEVERE, null, ex);
//            }
//        } finally {
//            Connect_DB.close(null, null, ps, con);
//        }
//        return re;
//    }
//    public static boolean setDisableLiking(String liking_Id) {
//        String up = "UPDATE [Matrimony].[dbo].[Liking_Cates]\n"
//                + "   SET [Liking_Status] = 0"
//                + " where [Liking_Id]=? ";
//        boolean re = false;
//        PreparedStatement ps = null;
//        Connection con=null;
//        try {
//            con = Connect_DB.getConnection();
//            ps = con.prepareStatement(up);
//            ps.setInt(1, Integer.parseInt(liking_Id));
//            int i = ps.executeUpdate();
//            if (i > 0) {
//                re = true;
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }finally{
//            Connect_DB.close(null, ps, ps, con);
//        }
//        return re;
//    }
}
